# 作者: 肖老师
# 2024年12月19日00时10分45秒
# xxxrlmk@163.com
MAXKEY = 1000


def elf_hash(hash_str):
    h = 0
    g = 0
    for i in hash_str:
        h = (h << 4) + ord(i)
        g = h & 0xf0000000
        if g:
            h ^= g >> 24
        h &= ~g
    return h % MAXKEY


def use_hash():
    str_list = ["xiongda", "lele", "hanmeimei", "wangdao", "fenghua"]
    hash_table = [None] * MAXKEY
    for i in str_list:
        # 判断是否发生哈希冲突
        if hash_table[elf_hash(i)] is not None:
            print('哈希冲突')
        else:
            hash_table[elf_hash(i)] = i  # 把字符串存储哈希表
    pass


use_hash()
